/**
 * 
 */
package es.cloudcast.persistence.dao.jdo;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;

/**
 * @author Samuel García Martínez <in0de>
 *
 */
public class PersistenceManagerFactory {
	
	private static String CONFIGURATION_FILENAME = "appengine-jdo.xml";
	
	private static javax.jdo.PersistenceManagerFactory PMF = 
		JDOHelper.getPersistenceManagerFactory(CONFIGURATION_FILENAME);
	
	private static ThreadLocal<PersistenceManager> currentPersistenceManager = 
											new ThreadLocal<PersistenceManager>();
	
	public javax.jdo.PersistenceManagerFactory getFactory() {
		return PMF;
	}
	
	public PersistenceManager getCurrentPersistenceManager() {
		if(currentPersistenceManager.get() != null ) {
			currentPersistenceManager.set(PMF.getPersistenceManager());
		}
		
		return currentPersistenceManager.get();
	}
	
}
